package com.mybatisPlusSpring;

import com.malred.mappers.personMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author malguy-wang sir
 * @create ---
 */
public class myFactoryBean implements FactoryBean {
    private SqlSession session;
    private Class mapperClass;
    public myFactoryBean(Class mapper) { this.mapperClass = mapper; }
    @Autowired
    public void setSqlSession(SqlSessionFactory factory){
        factory.getConfiguration().addMapper(mapperClass);
        this.session = factory.openSession(); }
    @Override
    public Object getObject() throws Exception {
        return session.getMapper(mapperClass);
        }
    @Override
    public Class<?> getObjectType() {
        return mapperClass; }
}
